# -*- coding: utf-8 -*-
# @Time    : 2022/10/25 15:23
# @Author  : 限量老
from django.http import HttpResponse
from django.shortcuts import redirect
from django.utils.deprecation import MiddlewareMixin

class AuthMiddleware(MiddlewareMixin):
    '''中间件1'''

    def process_request(self,request):

        #0.排除那些不需要登录就能访问的页面
        if request.path_info in ['/login/','/image/code/']: #获取当前用户请求的URL /login/和 /image/code/验证码生成器
            return #往后走

        #1,读取当前访问的用户的seeeion作息,如果能读到,说明已登录过,就可以继续向后走
        info_dict=request.session.get('info')
        if info_dict:
            return #往后走

        #2.如果没有登录过:回到登录页面
        return redirect('/login/')

    # def process_response(self,request,response):
    #     print('M1.走了')
    #     return response

















